package com.zj.config;

import com.zj.interceptor.AdminInterceptor;
import com.zj.interceptor.LoginInterceptor;
import com.zj.interceptor.RequestLimitInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {
    @Autowired
    LoginInterceptor loginInterceptor;
    @Autowired
    AdminInterceptor adminInterceptor;
    @Autowired
    RequestLimitInterceptor requestLimitInterceptor;
    public void addInterceptors(InterceptorRegistry registry) {
        //注册 限流拦截器
        registry.addInterceptor(requestLimitInterceptor).addPathPatterns("/**");
        //注册 登录拦截器
        registry.addInterceptor(loginInterceptor).
                addPathPatterns("/**").//拦截路径
                excludePathPatterns("/users/login","/users/register","/goods/public","/users");//放行路径
        //注册 登录后台权限拦截器
        registry.addInterceptor(adminInterceptor).addPathPatterns("/admin/**");

    }
}
